#ifndef SPLINES_H
#define SPLINES_H

#include <vector>
#include <cmath>
#include <map>
#include <Eigen/Dense>
#include "Polynomials.h"
#include <stdexcept>
#include "B_Basis_function.h"

//PP样条
class PPSplines{
    protected:
    std::vector<double> x;//节点x坐标
    std::vector<double> f;//节点f(x)值
    std::vector<Polynomial> poly;//存储分段多项式的系数
    public:
    PPSplines(const std::vector<double>& x_0,const std::vector<double>& f_0);
    virtual void CalculateCoefficients()=0;
    double value(const double& x_value);
};

double PPSplines::value(const double& x_value){
    for (size_t i = 0; i < x.size()-1; i++) {
            if (x_value >= x[i] && x_value <= x[i + 1]) {
                return poly[i].value(x_value);
            }
    }
        throw std::out_of_range("x_value is out of the spline's domain");
}
PPSplines::PPSplines(const std::vector<double>& x_0,const std::vector<double>& f_0):x(x_0),f(f_0){
    if(x.size()!=f.size()){
        throw std::invalid_argument("The size of x and f vectors must be the same");
    }
    poly.resize(x.size()-1);
}




//-----------------------B-------------------------//
class BSplines{
    public:
    std::vector<double> knots;
    std::vector<double> f;
    std::vector<double> coefficients;
    BSplines(std::vector<double> knots,std::vector<double> f);
    virtual void CalculateCoefficients()=0;
    virtual double B_value(double x_value)=0;
};
    BSplines::BSplines(std::vector<double> knots,std::vector<double> f):knots(knots),f(f){
        int n=knots.size();
        coefficients.resize(n+2);
    }


#endif